<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"  xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<title>SCB First to Enjoy</title>
	<link rel="stylesheet" href="css/global.css" media="all" />
	<link rel="stylesheet" href="css/style.css" media="all" />
	<script src="js/jquery.min.js"></script>
    </head>
    <body>
	<script src="//connect.facebook.net/en_US/all.js#"></script>
	<div id="fb-root"></div>
	<input type="hidden" id="fb-root-holder" />
	<script type="text/javascript">
	    window.fbAsyncInit = function() {
		FB.init({
		    appId: '{$fb_app_id}',
		    status: true,
		    cookie: true,
		    xfbml: true,
		    channelUrl : '{$site_url}template/home/channel.html' // Channel File
		});
		
		FB.Canvas.setSize({width: 810, height: 834});
	    };
	    // Load the SDK Asynchronously
	    (function(d){
	       var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
	       js = d.createElement('script'); js.id = id; js.async = true;
	       js.src = "//connect.facebook.net/en_US/all.js";
	       d.getElementsByTagName('head')[0].appendChild(js);
	     }(document));
	</script>
	
	<div id="wrapper" class="wrapper-sorry">
	    <div id="answer-order" class="{$answer_order_hidden}">
		<ul>
		    <li>คุณเข้ามาตอบคำถามเป็นลำดับที่ <span>{$answer_order}</span></li>
		    <li>จำนวนของรางวัลคงเหลือ <span>{$prizes_remain}</span> ชื้น</li>
		</ul>
	    </div>
	    
	    <div id="sorry-msg">
		<img src="images/{$sorry_img}" alt="{$sorry_title}" />
		<!--<img src="images/sorry-msg-today-win.png" alt="{$sorry_title}" />-->
	    </div>
	    
            <a href="javascript:void(0);" title="Next" id="sorry-bt" class="bt-fs-dialog">&nbsp;</a>
	    
	    <div class="hidden">
		<a href="#ajax-loader-block" id="ajax-loader" class="acolorbox">Please wait...</a>
		<div id="ajax-loader-block" style="padding:15px 10px 5px 10px;background:#000000;text-align:center;-webkit-border-radius: 10px;-moz-border-radius: 10px;border-radius: 10px;opacity: 0.7;color: #cccccc;">
		    <img src="images/284.gif" alt="Please wait..." style="width:60px;" />
		    <p>Please wait...</p>
		</div>
		
		<script type="text/javascript" src="js/fancybox/jquery.fancybox.pack.js"></script>
		<link rel="stylesheet" href="js/fancybox/jquery.fancybox.css" media="all" />
		<script type="text/javascript" src="js/jquery-friend-selector/jquery.friend.selector-1.1.min.js"></script>
		<link rel="stylesheet" href="js/jquery-friend-selector/jquery.friend.selector-1.1.css" />
		<script>
		    $(document).ready(function(){
			$('.acolorbox').fancybox({
			    'closeBtn':false,
			    'autoDimensions' : false,
			    'autoScale' : false,
			    'closeClick' : false,
			    'helpers' :  {
				overlay : {
				    closeClick: false
				}
			    }
			});
	    
			$(".bt-fs-dialog").fSelector({
			    max : 1,
			    'lang.buttonSubmit' : 'Confirm',
			    onSubmit: function(response){
				// example response usage
				var selected_friends = [];
				var is_selected = false;
				$.each(response, function(k, v){
				    selected_friends[k] = v;
				    is_selected = true;
				});
				
				if(is_selected){
				    send_to_friends(selected_friends[0]);
				}else{
				    alert("Please select your's friend.");
				}
				
			    },
			    onClose: function(response){
				post_to_wall();
			    }
			});
		    });
		    
		    function send_to_friends(friend_id)
		    {
			$('#fs-dialog-box-wrap').css('display','none');
			$('#fs-overlay').css('display','none');
			
			FB.ui({
				method: 'stream.publish',
				app_id: '{$fb_app_id}',
				display: 'iframe',
				name: 'FIRST TO ENJOY with SCB Credit card',
				link: '{$fb_page_url}',
				picture: '{$site_url}assets/images/icon.jpg',
				caption: 'ร่วมสนุกและลุ้นรับของรางวัลต่างๆ มากมาย',
				description: 'พร้อมติดตามเราอย่างต่อเนื่องที่ แฟนเพจ SCB CREDIT CARD',
				target_id: friend_id
			    },
			    function(response) {
				post_to_wall();
			    }
			);
		    }
		    
		    function post_to_wall()
		    {
			if($('#fb-root-holder').val() == ''){
			    $('#fb-root-holder').val('1');
			    FB.ui({
				    method: 'stream.publish',
				    app_id: '{$fb_app_id}',
				    display: 'iframe',
				    name: 'FIRST TO ENJOY with SCB Credit card',
				    link: '{$fb_page_url}',
				    picture: '{$site_url}assets/images/icon.jpg',
				    caption: 'ร่วมสนุกและลุ้นรับของรางวัลต่างๆ มากมาย',
				    description: 'พร้อมติดตามเราอย่างต่อเนื่องที่ แฟนเพจ SCB CREDIT CARD',
				},
				function(response) {
				    $('#ajax-loader').click();
				    window.location = '{$site_url}';
				}
			    );
			}
		    }
		</script>
	    </div>
        </div>
    </body>
</html>